﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module;

public partial class JSPost_Check : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string flg = Request.QueryString["flg"];
        if ("1".Equals(flg))
        {
            Response.Write(true);
            Response.End();
        }
        string action = Request["action"];
        if (!string.IsNullOrEmpty(action))
        {
            bool isTrue = false;

            switch (action)
            {
                case "checkEmail":
                    isTrue = isEmail(Request["name"]);
                    Response.Write(isTrue);
                    Response.End();
                    break;
                case "checkUserName":
                    isTrue = isUserName(Request["name"]);
                    Response.Write(isTrue);
                    Response.End();
                    break;
                case "checkPhone":
                    isTrue = isPhoneExist(Request["name"]);
                    Response.Write(isTrue);
                    Response.End();
                    break;
                case "checkRegionName":
                    isTrue = isRegionNameExist(Request["name"]);
                    Response.Write(isTrue);
                    Response.End();
                    break;
            }
        }
    }

    private bool isRegionNameExist(string titleName)
    {
        FamousRegionInfo famousRegionInfo = BLL.BFamousRegion.getInstance().GetFamousRegionInfoByTitle(titleName);
        if (famousRegionInfo != null && famousRegionInfo.FamousRegionId>0)
            return false;
        return true;
    }

    private bool isEmail(string p)
    {
        UserProfileInfo userProfile = BLL.BUserProfile.getInstance().GetUserProfileInfo(p);
        if (userProfile != null && userProfile.UserPassportId > 0)
            return false;
        return true;
    }

    private bool isUserName(string p)
    {
        UserPassportInfo user = BLL.BUserPassport.getInstance().GetUserPassportInfo(p);
        if (user != null && user.UserPassportId > 0)
            return false;
        return true;

    }
    private bool isPhoneExist(string p)
    {
        UserProfileInfo userProfile = BLL.BUserProfile.getInstance().GetUserProfileInfoByPhone(p);
        if (userProfile != null && userProfile.UserPassportId > 0)
            return false;
        return true;
    }
}